package cn.ycbjie.ycaudioplayer.ui.study.ui.adapter;

import android.app.Activity;
import android.provider.ContactsContract;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.synjones.minnovate.frame.basesdk.image.SynImage;
import com.synjones.minnovate.frame.basesdk.image.SynImageCropType;
import com.synjones.minnovate.frame.basesdk.image.SynImageOption;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.viewHolder.BaseViewHolder;

import cn.ycbjie.ycaudioplayer.R;
import cn.ycbjie.ycaudioplayer.inter.OnMoreClickListener;
import cn.ycbjie.ycaudioplayer.mybean.myhomemaibean;


public class StudyAdapter extends RecyclerArrayAdapter<myhomemaibean.DataBean.ResourcesBean> {
private  Activity activitys;
    public StudyAdapter(Activity activity) {

        super(activity);
        this.activitys = activity;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new VideoPlayerViewHolder(parent);
    }


    private class VideoPlayerViewHolder extends BaseViewHolder<myhomemaibean.DataBean.ResourcesBean> {

        ImageView img_homelist;
        TextView tv_home_title , tv_home_summary ,tv_home_sub_num,tv_home_id;
//        View view_color;

        VideoPlayerViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_study_news);
            img_homelist=$(R.id.img_homelist);
            tv_home_title=$(R.id.tv_home_title);
            tv_home_summary=$(R.id.tv_home_summary);
            tv_home_sub_num=$(R.id.tv_home_sub_num);
            tv_home_id=$(R.id.tv_home_id);
        }

        @Override
        public void setData(myhomemaibean.DataBean.ResourcesBean data) {
            super.setData(data);
            String uri = data.getCover();
            if(uri.startsWith("https")) {
                uri = uri.substring(0, 4) + uri.substring(5, uri.length());
            }
//            Glide.with(getContext()).load(uri)
//                    .apply(RequestOptions.bitmapTransform(new CircleCrop()).placeholder(R.drawable.default_cover))
//                    .into(img_homelist);
//            SynImageOption options = new SynImageOption();
//            options.setPlaceHolder(R.drawable.ic_launcher_background);
//            options.setImageCropType(SynImageCropType.CENTER_CROP);
//            SynImage.into(getContext(),data.getCover(),img_homelist);
            Glide.with(getContext())
                    .load(uri)
                    .into(img_homelist);
//            Glide.with(getContext()).load(data.getCover()).into(img_homelist);
//            String uri = data.getCover();
//            Glide.with(getContext()).load("http://ebook.qikan.com/bookpicture/ds056182.jpg")
//                    .apply(RequestOptions.bitmapTransform(new CircleCrop()).placeholder(R.drawable.default_cover))
//                    .into(img_homelist);
//            SynImage.into(activitys, data.getCover(),img_homelist);
            tv_home_title.setText(data.getTitle());
            try {
                tv_home_summary.setText(data.getSummary().toString());
            }
            catch (Exception ex)
            {

            }
            tv_home_id.setText(data.getId());
            tv_home_sub_num.setText(data.getSub_num()+"");

        }
    }
    private OnMoreClickListener mListener;
    void setOnMoreClickListener(OnMoreClickListener listener) {
        mListener = listener;
    }
}
